home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / 3DGPL 1.0 / CODE / HARDWARE / 8086-BCC / HARDWARE.C next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  4.2 KB  |  117 lines  |  [TEXT/MACA]

  1. /** 3DGPL *************************************************\
  2.  *  (MSDOS, 8086+, VGA, BCC/LARGE MODEL+)                 *
  3.  *  Header for hardware specific stuff.                   *
  4.  *                                                        *
  5.  *  Defines:                                              *
  6.  *    HW_open_screen         opening output surface;      *
  7.  *    HW_blit                colourmap onto the screen;   *
  8.  *    HW_close_screen        closing output;              *
  9.  *                                                        *
  10.  *    HW_run_event_loop      runiing for events;          *
  11.  *    HW_quit_event_loop     quiting running.             *
  12.  *                                                        *
  13.  *  (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca).     *
  14.  *  Copyright (c) 1995 Sergei Savchenko.                  *
  15.  *  THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
  16.  *  WITHOUT AUTHORISATION                                 *
  17. \**********************************************************/
  18.  
  19. #include <dos.h>                            /* MK_FP */
  20. #include <conio.h>                          /* kbhit(), getch() */
  21. #include "../hardware/hardware.h"           /* all the defenitions */
  22.  
  23. unsigned char *HW_colourmap;                /* where drwaings go to */
  24. int HW_running;                             /* event loop running? */
  25.  
  26. /**********************************************************\
  27.  *  Implementations for fast memory operations:           *
  28. \**********************************************************/
  29.  
  30. void HW_set_int(int *d,int l,int v) {int i; for(i=0;i<l;i++) *d++=v; }
  31.  
  32. /**********************************************************\
  33.  *  Opening output surface and setting the palette.       *
  34.  *                                                        *
  35.  *  RETURNS: always 1.                                    *
  36.  *  --------                                              *
  37. \**********************************************************/
  38.  
  39. int HW_open_screen(char *display_name,
  40.                    char *screen_name,
  41.                    struct HW_colour palette[256],
  42.                    unsigned char *colourmap
  43.                   )
  44. {
  45.  int i;
  46.  unsigned char r,g,b;
  47.  
  48.  HW_colourmap=colourmap;                    /* for later blits */
  49.  
  50.  asm mov al,13h                             /* %al mode number */
  51.  asm xor ah,ah                              /* function #0 */
  52.  asm int 10h
  53.  
  54.  for(i=0;i<256;i++)
  55.  {
  56.   r=(unsigned char)palette[i].hw_r;
  57.   g=(unsigned char)palette[i].hw_g;
  58.   b=(unsigned char)palette[i].hw_b;
  59.  
  60.   asm mov   dh,r                            /* Red */
  61.   asm mov   ch,g                            /* Green */
  62.   asm mov   cl,b                            /* Blue */
  63.   asm mov   bx,i                            /* Colour to set */
  64.   asm mov   ax,1010h                        /* function 0x10 subfun 0x10 */
  65.   asm int   10h
  66.  }
  67.  return(1);
  68. }
  69.  
  70. /**********************************************************\
  71.  *  Colormap onto the screen.                             *
  72. \**********************************************************/ 
  73.  
  74. void HW_blit(void)
  75. {
  76.  HW_copy_int((int*)HW_colourmap,(int*)MK_FP(0xa000,0x0000),HW_COLOURMAP_SIZE_INT);
  77. }
  78.  
  79. /**********************************************************\
  80.  *  Closing output surface.                               *
  81. \**********************************************************/
  82.  
  83. void HW_close_screen(void)
  84. {
  85. }
  86.  
  87. /**********************************************************\
  88.  *  Running the event loop.                               *
  89. \**********************************************************/
  90.  
  91. void HW_run_event_loop(void (*application_main)(void),
  92.                        void (*application_key_handler)(int key_code)
  93.                       )
  94. {
  95.  int k;
  96.  
  97.  HW_running=1;
  98.  
  99.  while(HW_running==1)                       /* still running? hmm */
  100.  {
  101.   if(kbhit()) if((k=getch())==0x0) application_key_handler(getch());
  102.               else application_key_handler(k);
  103.   application_main();
  104.  }
  105. }
  106.  
  107. /**********************************************************\
  108.  *  Stoping the event loop.                               *
  109. \**********************************************************/
  110.  
  111. void HW_quit_event_loop(void)
  112. {
  113.  HW_running=0;                              /* that's it */
  114. }
  115.  
  116. /**********************************************************/
  117.